<%@ page import="com.neuedu.entity.Dept" %>
<%@ page import="java.util.List" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<html>
<head>
    <title>Title</title>
	<script>

		function  deleteById(deptno){
			if(confirm("删不删?????")){
				let xhr = new XMLHttpRequest();

				xhr.onreadystatechange = function(){
					if( xhr.readyState==4 && xhr.status==200){
						let result  = eval( "("+xhr.responseText+")" );// result  Object (JSON)
						// result  {'status':true}
						// result  {'status':false}
						if(result.status){
							//提示成功路s
							alert("删除成功了");

							//刷新页面

							window.location = window.location;




						}else{
							alert("删除失败了，")
						}
					}
				}
				const url = "${pageContext.request.contextPath}/dept?_type=ajaxDeleteById&deptno="+deptno;
				alert("ajax url : "+url)
				xhr.open("GET",url,false);
				xhr.send();

			}

		}
	</script>
</head>
<body>




<h3>	MVC架构222221 </h3>
      <a href="${pageContext.request.contextPath}/emp?_type=toAdd">部门添加</a>
       <table border="1" width="500px"  cellpadding="0" cellspacing="0">
           	<tr align="center">                                                  
               		<td>部门id</td>                                                      
               		<td>部门名称</td>                                                      
               		<td>办公地址</td>                                                      
               		<td>操作</td>                                                      
               	</tr>

			<c:forEach items="${deptList}" var="dept" varStatus="stats">
					<tr align="center">
							<td> ${dept.deptno}</td>
							<td> ${dept.dname}</td>
							<td> ${dept.loc}</td>

							<td>
								  <a href='${pageContext.request.contextPath}/dept?_type=toEdit&deptno=${dept.deptno}'>修改</a>   &nbsp;&nbsp;&nbsp;&nbsp;
								  <a href='${pageContext.request.contextPath}/dept?_type=deleteById&deptno=${dept.deptno}'>删除</a>   &nbsp;&nbsp;&nbsp;&nbsp;
								  <button onclick="deleteById('${dept.deptno}')">删除</button>
							   </td>
						</tr>
			</c:forEach>


		  </table>



</body>
</html>
